import pymysql


class MysqlUtils(object):
    db = pymysql.connect("localhost",
                         "root",
                         "123456",
                         "python_test",
                         charset='utf8')

    def __init__(self, *args):
        self.args = args

    def get_mysql_connection(self):
        # 得到游标
        # 获取操作游标
        cursor = self.db.cursor()
        db = self.db
        # print(cursor,db)
        return db

    # 释放资源
    def release(self, db):
        self.db.close()

# mysqlT=MysqlUtils()
# mysqlT.get_mysql_connection()

# def __test(self):
#     listname = [
#         'zhangsan5'
#     ]
#
#     name = 'zhangsan3'
#
#     sqlist2 = 'insert into spidertest values(%s)', [name]
#     print(sqlist2)
#     try:
#         # cursor.execute(insertsql)
#         cursor.execute("insert into spidertest(name) values(%s)", 'lisi')
#         rs = cursor.fetchone()
#         print(rs)
#         db.commit()
#     # print(cursor.rowcount)
#     # for each in cursor.fetchmany(2):
#     #     print(each)
#     except:
#         db.rollback()
#
#     # g关闭链接
#     db.close()
#     # print(db)
